
var tableIns = '';
layui.use(['form', 'table','tfApi'], function () {
    var $ = layui.jquery,
        table = layui.table,
        API = layui.tfApi;

    //console.log("API.invoice.qryBills="+API.invoice.qryBills);

    API.postAjax('/invoice/qryDetailTotal ',{},function (res) {
        if(res.code == 0){
            var data = res.data,
                storage = localStorage,//window.sessionStorage,
                sellerNameLogin = storage.getItem("sellerName");


            var totalCharge = API.numFun(data.totalCharge) || '0.00',
                totalBill = API.numFun(data.totalBill) || '0.00',
                cnt = API.numFun(data.surplusAmt) || '0.00';

            $("#gs").html('<b>'+sellerNameLogin+'</b>');
            $("#Total").html('<b>'+totalCharge+'</b>');
            $("#ykp").html('<b>'+totalBill+'</b>');
            $("#sykp").html('<b>'+cnt+'</b>');
        }




    });

    table.render({
        elem: '#invoiceTable',
        url: API.CURL + API.invoice.qryBills,
        method: "POST",
        contentType: 'application/json',
        xhrFields: {withCredentials: true},crossDomain: true,
        request:{
            pageName: "page",
            limitName : "pageSize"
        },
        parseData: function(res){ //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.details, //解析数据列表
            };
        },
        defaultToolbar: ['filter', 'exports', 'print', {
            title: '提示',
            layEvent: 'LAYTABLE_TIPS',
            icon: 'layui-icon-tips'
        }],
        cols: [[
            {field: 'sellerId',title: 'sellerId', hide: true},
            {field: 'serviceId',title: 'serviceId', hide: true},
            {field: 'billCode', title: '发票编号'},
            {field: 'billNumber', title: '发票号'},
            {field: 'expressCode', title: '快递单号'},
            {field: 'billTypeId', title: '发票类型',toolbar:"#billType",align:'center'},
            {field: 'sellerCompanyName', title: '发票抬头', minWidth: 150},
            {field: 'taxableTotal', title: '开票金额' ,templet:function (d) {
                    var _s = API.numFun(d.taxableTotal);
                    return '<b>'+_s+'</b>';
                }},
            {title: '收件人信息',templet:"#sjrBox"},
            {field: 'serviceName', title: '开票公司'},
            {field: 'createTime', title: '申请时间',templet:function (d) {
                    var _t = d.createTime.split(" ");
                    return '<span>'+_t[0]+'</span><br><span>'+_t[1]+'</span>';
                }},
            {field: 'remark', title: '备注'},
            {field: 'status', title: '状态', width: 80, toolbar:"#staBar"}
        ]],
        id: 'invoiceReload',
        page: true,
        height : 'auto'
    });


    function reloadFun(s){
        var _data = {};
        if(s == 'all'){
            _data = {status: "-1"};
        }
        if(s == 'y'){
            _data = {status: "0"};
        }
        if (s == 'd'){
            _data = {status: "1"};
        }
        //执行重载
        table.reload('invoiceReload', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: _data
        }, 'data');
    }

    $('.shaixuan_btn_list a').on('click', function(){
        $(".shaixuan_btn_list a").removeClass('cur');
        $(this).addClass("cur");
        var state = $(this).data('state');
        //active['reload'] ? active['reload'].call(this) : '';
        reloadFun(state);
        console.log("state=="+state);
    });

});
